home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / GSRC208A.ZIP / GEP1.C < prev    next >
C/C++ Source or Header  |  1993-07-07  |  18KB  |  621 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*          GWTOP - Topology         */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*       Initialization and some     */
  14. /*           data structures         */
  15. /*                                   */
  16. /*           QuickC/WIN 1.0          */
  17. /*                                   */
  18. /*   (include here compilers that    */
  19. /*   compiled GWSIM successfully)    */
  20. /*                                   */
  21. /*************************************/
  22.  
  23.  
  24. #include <windows.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <io.h>
  29. #include <sys\types.h>
  30. #include <sys\stat.h>
  31. #include "globals.h"
  32. #include "topgvar.h"
  33. #include "strtbl.h"
  34. #include "gwtop.h"
  35. #include "iotop.h"
  36.  
  37. struct kint {
  38.                   unsigned char nsub;
  39.                 unsigned char npro;
  40.                 unsigned char nmodf;
  41.                 unsigned char revers;
  42.                 int idx;
  43.                 LPSTR descr;
  44.                };
  45.  
  46. struct nodet{
  47.              char item;
  48.              unsigned char val;
  49.              unsigned char left;
  50.              unsigned char right;
  51.             } ;
  52.  
  53. struct treet{
  54.              struct nodet node[256];
  55.              char id[64][10];
  56.              float constant[32];
  57.              int nnode,
  58.                  nnum,
  59.                  nid,
  60.                  nsub,
  61.                  npro,
  62.                  nmodf,
  63.                  nconst,
  64.                  revers;
  65.              char descr[64];
  66.             } ;
  67.  
  68.  
  69. GLOBALHANDLE hMetname;                                /* handle to memory block w/ metname    */
  70. GLOBALHANDLE hStepname;                                /* handle to memory block w/ stepname    */
  71. GLOBALHANDLE hStoiu;                                /* handle to memory block w/ stoiu        */
  72. GLOBALHANDLE hLoop;                                    /* handle to memory block w/ loop        */
  73. GLOBALHANDLE hKtype;                                /* handle to memory block w/ ktype        */
  74. GLOBALHANDLE hRstr;                                    /* handle to memory block w/ rstr        */
  75. GLOBALHANDLE hTree;                                    /* handle to memory block w/ tree        */
  76.  
  77. char    (huge *metname)[NAME_L];                    /* pointer to work with metname array    */
  78. char    (huge *stepname)[NAME_L];                    /* metabolite names                        */
  79. int        huge *stoiu;                                /* pointer to work with metname array    */
  80. unsigned char (huge *loop)[MAX_STEP][MAX_MET];        /* def. of modification loops            */
  81. int     (huge *rstr)[MAX_STEP][MAX_MOL];            /* reaction structure                    */
  82. char    topname[256];                                /* title for the topology                */
  83. double    xu[MAX_MET];                                /* concentrations at time t user        */
  84. int        intmet[MAX_MET];                            /* 1 if internal metabolite                */
  85. unsigned char    revers[MAX_STEP];                    /* 1 if reaction is reversible            */
  86. int        kinetu[MAX_STEP];                            /* type of kinetics (user numb.)        */
  87. int        kfl[MAX_STEP];                                /* flags for input of user-def.kinetics */
  88. unsigned char    nmod[MAX_STEP];                        /* number of assigned modfs of a react.    */
  89. struct    kint huge *ktype;                            /* ptr array of kinetic types & proprt    */
  90. double    endtime;                                    /* time value for last iteration        */
  91. double    hrcz;                                        /* highest rate considered zero            */
  92. double    dft_endtime;                                /* time value for last iteration        */
  93. double    dft_hrcz;                                    /* highest rate considered zero            */
  94. float    ver_no;                                        /* .top and .sim version number            */
  95. int        totmet;                                        /* number of total metabolites            */
  96. int        nmetab;                                        /* number of internal metabolites        */
  97. int        nsteps;                                        /* number of steps                        */
  98. int        nloops;                                        /* number of modifier loops             */
  99. int        nrateq;                                        /* number of kinetic types in the datab */
  100. int        newtree;                                    /* 1 if user added kinetic new types    */
  101. int        nudf;                                        /* number of user-defined kin. types    */
  102. int        debugval;                                    /* debug mode                            */
  103. int        dft_debugval;                                /* debug mode                            */
  104. int        options;                                    /* various options                        */
  105. struct    treet huge *tree;                            /* function tree for rate equations        */
  106. struct    treet tr;                                    /* tree for the input                    */
  107.  
  108. /* Initialization of GEPASI's variables */
  109.  
  110. int InitGepasiVar( void )
  111. {
  112.  int i, j;
  113.  
  114.  hMetname = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * NAME_L * sizeof( char ) );
  115.  if( hMetname == NULL ) return -1;
  116.  
  117.  hStepname = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_STEP * NAME_L * sizeof( char ) );
  118.  if( hStepname == NULL )
  119.  {
  120.   GlobalFree( hMetname );
  121.   return -1;
  122.  }
  123.  
  124.  hStoiu = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * MAX_STEP * sizeof( int ) );
  125.  if( hStoiu == NULL )
  126.  {
  127.   GlobalFree( hMetname );
  128.   GlobalFree( hStepname );
  129.   return -1;
  130.  }
  131.  
  132.  hLoop = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_STEP * MAX_MET * sizeof( unsigned char ) );
  133.  if( hLoop == NULL )
  134.  {
  135.   GlobalFree( hMetname );
  136.   GlobalFree( hStepname );
  137.   GlobalFree( hStoiu );
  138.   return -1;
  139.  }
  140.  
  141.  hKtype = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_TYP * sizeof( struct kint ) );
  142.  if( hKtype == NULL )
  143.  {
  144.   GlobalFree( hMetname );
  145.   GlobalFree( hStepname );
  146.   GlobalFree( hStoiu );
  147.   GlobalFree( hLoop );
  148.   return -1;
  149.  }
  150.  
  151.  hRstr = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MOL * MAX_STEP * sizeof( int ) );
  152.  if( hRstr == NULL )
  153.  {
  154.   GlobalFree( hMetname );
  155.   GlobalFree( hStepname );
  156.   GlobalFree( hStoiu );
  157.   GlobalFree( hLoop );
  158.   GlobalFree( hKtype );
  159.   return -1;
  160.  }
  161.  
  162.  nudf = 0;
  163.  hTree = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) sizeof( struct treet ) );
  164.  if( hTree == NULL )
  165.  {
  166.   GlobalFree( hMetname );
  167.   GlobalFree( hStepname );
  168.   GlobalFree( hStoiu );
  169.   GlobalFree( hLoop );
  170.   GlobalFree( hKtype );
  171.   GlobalFree( hRstr );
  172.   return -1;
  173.  }
  174.  
  175.  metname    = ( char (huge *)[NAME_L] ) GlobalLock( hMetname );
  176.  stepname    = ( char (huge *)[NAME_L] ) GlobalLock( hStepname );
  177.  stoiu        = ( int huge * ) GlobalLock( hStoiu );
  178.  loop        = ( unsigned char (huge *)[MAX_STEP][MAX_MET] ) GlobalLock( hLoop );
  179.  ktype        = ( struct kint huge * ) GlobalLock( hKtype );
  180.  rstr        = ( int (huge *)[MAX_STEP][MAX_MOL] ) GlobalLock( hRstr );
  181.  tree        = ( struct treet huge * ) GlobalLock( hTree );
  182.  
  183.  newtree = 0;
  184.  
  185.  for( i=0; i<MAX_MET; i++ ) intmet[i] = 1;            /* set all metb. to be internal    */
  186.  totmet = nmetab = nsteps = 0;                        /* clear no. of metb. and steps    */
  187.  
  188.  nrateq = MAX_TYP;                                  /* set the no. of kinetic types */
  189.  ktype[NOT].nsub = 0;                                /* init info of kinetic types    */
  190.  ktype[NOT].npro = 0;
  191.  ktype[NOT].revers = -1;
  192.  ktype[NOT].nmodf = 0;
  193.  ktype[NOT].descr = (LPSTR) "<not defined>";
  194.  ktype[I01].nsub = 0;
  195.  ktype[I01].npro = 0;
  196.  ktype[I01].revers = 0;
  197.  ktype[I01].nmodf = 0;
  198.  ktype[I01].descr = (LPSTR) "constant rate";
  199.  ktype[I10].nsub = 20;
  200.  ktype[I10].npro = 20;
  201.  ktype[I10].revers = 0;
  202.  ktype[I10].nmodf = 0;
  203.  ktype[I10].descr = (LPSTR) "no type";
  204.  ktype[I11].nsub = 1;
  205.  ktype[I11].npro = 1;
  206.  ktype[I11].revers = 0;
  207.  ktype[I11].nmodf = 0;
  208.  ktype[I11].descr = (LPSTR) "mass action";
  209.  ktype[R11].nsub = 1;
  210.  ktype[R11].npro = 1;
  211.  ktype[R11].revers = 1;
  212.  ktype[R11].nmodf = 0;
  213.  ktype[R11].descr = (LPSTR) ktype[I11].descr;
  214.  ktype[I21].nsub = 2;
  215.  ktype[I21].npro = 1;
  216.  ktype[I21].revers = 0;
  217.  ktype[I21].nmodf = 0;
  218.  ktype[I21].descr = (LPSTR) ktype[I11].descr;
  219.  ktype[R21].nsub = 2;
  220.  ktype[R21].npro = 1;
  221.  ktype[R21].revers = 1;
  222.  ktype[R21].nmodf = 0;
  223.  ktype[R21].descr = (LPSTR) ktype[I11].descr;
  224.  ktype[I12].nsub = 1;
  225.  ktype[I12].npro = 2;
  226.  ktype[I12].revers = 0;
  227.  ktype[I12].nmodf = 0;
  228.  ktype[I12].descr = (LPSTR) ktype[I11].descr;
  229.  ktype[R12].nsub = 1;
  230.  ktype[R12].npro = 2;
  231.  ktype[R12].revers = 1;
  232.  ktype[R12].nmodf = 0;
  233.  ktype[R12].descr = (LPSTR) ktype[I11].descr;
  234.  ktype[I31].nsub = 3;
  235.  ktype[I31].npro = 1;
  236.  ktype[I31].revers = 0;
  237.  ktype[I31].nmodf = 0;
  238.  ktype[I31].descr = (LPSTR) ktype[I11].descr;
  239.  ktype[R31].nsub = 3;
  240.  ktype[R31].npro = 1;
  241.  ktype[R31].revers = 1;
  242.  ktype[R31].nmodf = 0;
  243.  ktype[R31].descr = (LPSTR) ktype[I11].descr;
  244.  ktype[I13].nsub = 1;
  245.  ktype[I13].npro = 3;
  246.  ktype[I13].revers = 0;
  247.  ktype[I13].nmodf = 0;
  248.  ktype[I13].descr = (LPSTR) ktype[I